﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Tauren.Business.Infrastructure.Common;
using Tauren.Business.Service.Employee;

namespace Tauren.Business.Core.Controllers
{
    /// <summary>
    /// 员工基本信息
    /// </summary>
    [Route("api/emp"), ApiVersion("1.0")]
    [ApiController]
    public class EmployeeController : ControllerBase
    {
        private IEmployeeService service { get; set; }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_service"></param>
        public EmployeeController(IEmployeeService _service)
        {
            service = _service;
        }

        /// <summary>
        /// 新增员工基本信息
        /// </summary>
        /// <param name="input">租户信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/add")]
        public IActionResult Add([FromBody] Entity.Input.Employee_input input) => service.Add(input).ToJsonResult();


        /// <summary>
        /// 编辑员工基本信息
        /// </summary>
        /// <param name="input">租户信息</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/edit")]
        public IActionResult Editor([FromBody] Entity.Input.Employee_input input) => service.Editor(input).ToJsonResult();

        /// <summary>
        /// 获取单个员工基本信息数据
        /// </summary>
        /// <param name="id">人员基本信息实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/get/{id}")]
        public IActionResult Get([FromRoute] int id) => service.FirstOrDefault(id).ToJsonResult(); 

        /// <summary>
        /// 删除人员基本信息信息
        /// </summary>
        /// <param name="id">人员基本信息实体id</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/del/{id}")]
        public IActionResult Delete([FromRoute] int id) => service.Delete(id).ToJsonResult();

         
        /// <summary>
        /// 获取人员基本信息信息--多个--根据编码
        /// </summary> 
        /// <param name="code">人员基本信息编码</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/code/{code}")]
        public IActionResult GetByCode([FromRoute] string code) => service.GetByCode(code).ToJsonResult();


        /// <summary>
        /// 获取人员基本信息信息--根据empids集合
        /// </summary> 
        /// <param name="empids">empids集合</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/empids")]
        public IActionResult GetListByEmpIds([FromBody] List<string> empids) => service.GetListByEmpIds(empids).ToJsonResult();

        /// <summary>
        /// 获取人员基本信息信息--获取所有集合
        /// </summary>  
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/getall")]
        public IActionResult GetAll() => service.GetAll().ToJsonResult();

        /// <summary>
        /// 获取所有数据
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/all")]
        public IActionResult All() => service.All().ToJsonResult();

        /// <summary>
        /// 分页获取员工信息列表（不含兼职）
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/pages")]
        public IActionResult Pages([FromBody] Entity.Global.QueryModel queryModel) => service.Pages(queryModel).ToJsonResult();

        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="id">员工ID</param>
        /// <returns></returns>
       [HttpPost,Route("v{version:apiVersion}/physicaldelete/{id:int}")]
        public IActionResult PhysicalDelete([FromRoute]int id) => service.PhysicalDelete(id).ToJsonResult();

        /// <summary>
        /// 启用??
        /// </summary>
        /// <param name="id">员工ID</param> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/enable/{id:int}")]
        public IActionResult Enable(int id) => service.Enable(id).ToJsonResult();

        /// <summary>
        /// 根据组织获取员工基本信息
        /// </summary>
        /// <param name="orgId">组织ID</param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/orgs/{orgId}")]
        public IActionResult GetByOrgs([FromRoute] string orgId) => service.GetByOrgs(orgId).ToJsonResult();
        /// <summary>
        /// 获取当前用的基本信息
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/currentuser")]
        public IActionResult GetCurrentUser() => service.GetCurrentUser().ToJsonResult();

        /// <summary>
        /// 获取组织的弹出框树形结构
        /// </summary> 
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/tree")]
        public IActionResult Tree() => service.Tree().ToJsonResult(true);
        /// <summary>
        /// 获取字段数据
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/config/{type}")]
        public IActionResult Config([FromRoute] string type) => service.Config(type).ToJsonResult(true);

        /// <summary>
        /// 分页获取 账号信息列表
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/acc")]
        public IActionResult DialogEmps([FromBody] Entity.Global.QueryModel queryModel) => service.DialogEmps(queryModel).ToJsonResult();

        /// <summary>
        /// 获取流程中的员工
        /// </summary>
        /// <param name="queryModel"></param>
        /// <returns></returns>
        [HttpPost, Route("v{version:apiVersion}/flowemp")]
        public IActionResult FlowEmps([FromBody] Entity.Global.QueryModel queryModel) => service.FlowEmps(queryModel).ToJsonResult();
    }
}
